//
//  ICMGetCarBasicInfoView.m
//  ICrEAM
//
//  Created by FoREVer_SaD on 16/10/26.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ICMGetCarBasicInfoView.h"
#import "SelectAreaPrefixView.h"
#import "ICMBasicInfoModel.h"
#import "ICMAppointmentOtherInfoModel.h"
#import "ICMPersonerModel.h"
#import "ICMInputAreaView.h"

#define xDistanceA                  ActualWidth(25)
#define xDistanceB                  ActualWidth(50)
#define yDistance                   ActualHeight(25)
#define TitleTFViewHeight           ActualHeight(63)
#define TitleTViewHeight            ActualHeight(90)

@interface ICMGetCarBasicInfoView ()<SelectAreaPrefixViewDelegate,ICMTitleTextFeildViewDelegate,ICMInputAreaViewDelegate>

@property (nonatomic, strong) UIView *remainingFuelView;

@property (nonatomic, strong) UIImageView *oilIndicator;

@property (nonatomic, strong) NSMutableArray *selectedRepairTypes;

@property (nonatomic, strong) UIView *blankView;

@property (nonatomic, strong) TPKeyboardAvoidingScrollView *bigScrollView;

@property (nonatomic, strong) SelectAreaPrefixView *selectAreaPrefixView;

//车牌号选择其他后弹出的输入界面
@property (nonatomic, strong) ICMInputAreaView *inputAreaView;

@end

@implementation ICMGetCarBasicInfoView

- (SelectAreaPrefixView *)selectAreaPrefixView {
    if (!_selectAreaPrefixView) {
        _selectAreaPrefixView = [[SelectAreaPrefixView alloc] initWithFrame:CGRectMake(ActualWidth(207), ActualHeight(230), ActualWidth(630), ActualHeight(185))];
        _selectAreaPrefixView.delegate = self;
    }
    return _selectAreaPrefixView;
}

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */
#pragma mark    初始化
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self){
        self.bigScrollView = [[TPKeyboardAvoidingScrollView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(frame), CGRectGetHeight(frame))];
        self.bigScrollView.backgroundColor = [UIColor clearColor];
        
        self.haveChangeVIN = YES;
        self.haveChangeCarModel = YES;
        self.backgroundColor = BackgroundColor_White;
        //第一行
        ICMTitleTextFeildView *vinNumberView = [ICMTitleTextFeildView createEditableICMTitleTextFeildViewWithFrame:CGRectMake(ActualWidth(20), yDistance, ActualWidth(220), TitleTFViewHeight) title:@"VIN"];
        vinNumberView.delegate = self;
        vinNumberView.limitedNum = 17;
        [self.bigScrollView addSubview:vinNumberView];
        
        ICMTitleTextFeildView *selectAreaView = [ICMTitleTextFeildView createClickableICMTitleTextFeildViewWithFrame:CGRectMake(vinNumberView.rightEdge+xDistanceA, vinNumberView.y, ActualWidth(65), TitleTFViewHeight) title:@"车牌号" addTarget:self selector:@selector(clickSelectAreaView:)];
        [self.bigScrollView addSubview:selectAreaView];
        
        ICMTitleTextFeildView *plateNumberView = [ICMTitleTextFeildView createEditableICMTitleTextFeildViewWithFrame:CGRectMake(selectAreaView.rightEdge, selectAreaView.y, ActualWidth(155), TitleTFViewHeight) title:@" "];
        plateNumberView.contentTextFeild.keyboardType = UIKeyboardTypeDefault;
        plateNumberView.delegate = self;
//        plateNumberView.limitedNum = 7;
        plateNumberView.contentTextFeild.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
        [self.bigScrollView addSubview:plateNumberView];
        
        ICMTitleTextFeildView *ownerNameView = [ICMTitleTextFeildView createNoneditableICMTitleTextFeildViewWithFrame:CGRectMake(plateNumberView.rightEdge+xDistanceB, plateNumberView.y, ActualWidth(465), TitleTFViewHeight) title:@"车主姓名"];
        [self.bigScrollView addSubview:ownerNameView];
        
        self.vinNumberView = vinNumberView;
        self.vinNumberView.isUppercase = YES;
        self.selectAreaView = selectAreaView;
        self.plateNumberView = plateNumberView;
        self.plateNumberView.isUppercase = YES;
        self.ownerNameView = ownerNameView;
        
        //第二行
        ICMTitleTextFeildView *invoiceDateView = [ICMTitleTextFeildView createNoneditableICMTitleTextFeildViewWithFrame:CGRectMake(vinNumberView.x, vinNumberView.bottomEdge+yDistance, ActualWidth(220), TitleTFViewHeight) title:@"购车发票日期"];
        [self.bigScrollView addSubview:invoiceDateView];
        
        ICMTitleTextFeildView *currentMileageView = [ICMTitleTextFeildView createEditableICMTitleTextFeildViewWithFrame:CGRectMake(invoiceDateView.rightEdge+xDistanceA, invoiceDateView.y, ActualWidth(220), TitleTFViewHeight) title:@"当前行驶里程(KM)"];
        currentMileageView.contentTextFeild.keyboardType=UIKeyboardTypeNumberPad;
        currentMileageView.delegate = self;
        currentMileageView.signStr = @"mileage";
        self.currentMileageView = currentMileageView;
        [self.bigScrollView addSubview:currentMileageView];
        
        
        
        
        
        ICMTitleTextFeildView *ownerPhoneNumberView = [ICMTitleTextFeildView createNoneditableICMTitleTextFeildViewWithFrame:CGRectMake(currentMileageView.rightEdge+xDistanceB, currentMileageView.y, ActualWidth(220), TitleTFViewHeight) title:@"车主手机"];
        [self.bigScrollView addSubview:ownerPhoneNumberView];
        
        ICMTitleTextFeildView *ownerTypeView = [ICMTitleTextFeildView createNoneditableICMTitleTextFeildViewWithFrame:CGRectMake(ownerPhoneNumberView.rightEdge+xDistanceA, ownerPhoneNumberView.y, ActualWidth(220), TitleTFViewHeight) title:@"车主性质"];
        [self.bigScrollView addSubview:ownerTypeView];
        
        self.invoiceDateView = invoiceDateView;
        self.currentMileageView = currentMileageView;
        self.ownerPhoneNumberView = ownerPhoneNumberView;
        self.ownerTypeView = ownerTypeView;
        
        //第三行
        ICMTitleTextFeildView *carTypeView = [ICMTitleTextFeildView createNoneditableICMTitleTextFeildViewWithFrame:CGRectMake(invoiceDateView.x, invoiceDateView.bottomEdge+yDistance, ActualWidth(270), TitleTFViewHeight) title:@"车型"];
        [self.bigScrollView addSubview:carTypeView];
        
        //油量表
        UIView *remainingFuelView = [[UIView alloc] initWithFrame:CGRectMake(carTypeView.rightEdge+xDistanceA, invoiceDateView.bottomEdge, ActualWidth(155), ActualHeight(carTypeView.height+yDistance))];
        remainingFuelView.backgroundColor = [UIColor clearColor];
        [self.bigScrollView addSubview:remainingFuelView];
        self.remainingFuelView = remainingFuelView;
        
        UILabel *oilTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(ActualWidth(5), yDistance, ActualWidth(40), ActualHeight(20))];
        [oilTitleLabel setUpLabelWithText:@"油量" alignment:NSTextAlignmentLeft textSize:TitleSize textColor:TitleColor_Dark];
        [remainingFuelView addSubview:oilTitleLabel];
        
        UIImageView *remainingFuelImageView = [[UIImageView alloc] initWithFrame:CGRectMake(oilTitleLabel.rightEdge+ActualWidth(10), ActualHeight(8), ActualWidth(95), ActualHeight(50))];
        remainingFuelImageView.image = [UIImage imageNamed:GetCar_OilMeter];
        remainingFuelImageView.contentMode = UIViewContentModeScaleAspectFit;
        [remainingFuelView addSubview:remainingFuelImageView];
        
        UIImageView *oilIndicator = [[UIImageView alloc] initWithImage:[UIImage imageNamed:GetCar_OilMeterNeedle]];
        oilIndicator.frame = CGRectMake(oilTitleLabel.rightEdge+ActualWidth(14.5), ActualHeight(53.5), ActualWidth(46), ActualHeight(4));
        oilIndicator.contentMode = UIViewContentModeScaleToFill;
        self.oilIndicator = oilIndicator;
        [remainingFuelView addSubview:oilIndicator];
        
        UILabel *remainingFuelLabel = [[UILabel alloc] initWithFrame:CGRectMake(oilTitleLabel.rightEdge+ActualWidth(66), ActualHeight(45), ActualWidth(40), ActualWidth(15))];
        [remainingFuelLabel setUpLabelWithText:@"" alignment:NSTextAlignmentLeft textSize:ContentSize textColor:ContentTextColor_Black];
        self.remainingFuelLabel = remainingFuelLabel;
        [self setupRemainingFuelView];
        [remainingFuelView addSubview:remainingFuelLabel];
        
        UISlider *remainingFuelSlider = [[UISlider alloc] initWithFrame:CGRectMake(0, remainingFuelView.height-ActualHeight(16), remainingFuelView.width, ActualHeight(16))];
        remainingFuelSlider.value = 0.0;
        remainingFuelSlider.minimumValue = 0.0;
        remainingFuelSlider.maximumValue = 10.0;
        remainingFuelSlider.minimumTrackTintColor = TitleColor;
        [remainingFuelSlider addTarget:self action:@selector(remainingFuelSliderChanged:) forControlEvents:UIControlEventValueChanged];
        [remainingFuelView addSubview:remainingFuelSlider];
        self.remainingFuelSlider = remainingFuelSlider;
        
        ICMTitleTextFeildView *customerNameView = [ICMTitleTextFeildView createEditableICMTitleTextFeildViewWithFrame:CGRectMake(ownerPhoneNumberView.x, carTypeView.y, ActualWidth(220), TitleTFViewHeight) title:@"送修人姓名"];
        [self.bigScrollView addSubview:customerNameView];
        
        ICMTitleTextFeildView *customerPhoneNumberView = [ICMTitleTextFeildView createEditableICMTitleTextFeildViewWithFrame:CGRectMake(customerNameView.rightEdge+xDistanceA, customerNameView.y, ActualWidth(220), TitleTFViewHeight) title:@"送修人手机"];
        [self.bigScrollView addSubview:customerPhoneNumberView];
        
        self.carTypeView = carTypeView;
        self.customerNameView = customerNameView;
        self.customerPhoneNumberView = customerPhoneNumberView;
        
        //第四行
        ICMTitleTextFeildView *cleanCarView = [ICMTitleTextFeildView createClickableICMTitleTextFeildViewWithFrame:CGRectMake(carTypeView.x, carTypeView.bottomEdge+ActualHeight(45), ActualWidth(138), TitleTFViewHeight) title:@"洗车" addTarget:nil selector:nil];
        NSArray *cleanCarDataArray = [ICrEAMTool getParameterArrayWithCode:@"3550"];
        cleanCarView.clickDataArray = [[ICrEAMTool getParameterTitleArrayWithArray:cleanCarDataArray] mutableCopy];
        [self.bigScrollView addSubview:cleanCarView];

        ICMTitleTextFeildView *oldPartsShowView = [ICMTitleTextFeildView createClickableICMTitleTextFeildViewWithFrame:CGRectMake(cleanCarView.rightEdge+xDistanceA, cleanCarView.y, cleanCarView.width, TitleTFViewHeight) title:[ICrEAMTool isVW]?@"旧件展示":@"旧件是否带回" addTarget:nil selector:nil];
        NSArray *oldPartsDataArrayVM = [ICrEAMTool getParameterArrayWithCode:ICMEnumIntToString(ICMEnumOldPartProcessVWPre)];
        NSArray *oldPartsDataArraySK = [ICrEAMTool getParameterArrayWithCode:ICMEnumIntToString(ICMEnumOldPartProcessSKPre)];
        oldPartsShowView.clickDataArray = [[ICrEAMTool getParameterTitleArrayWithArray:[ICrEAMTool isVW]?oldPartsDataArrayVM:oldPartsDataArraySK] mutableCopy];
        [self.bigScrollView addSubview:oldPartsShowView];
        
        ICMTitleTextFeildView *spareWheelCheckView = [ICMTitleTextFeildView createClickableICMTitleTextFeildViewWithFrame:CGRectMake(oldPartsShowView.rightEdge+xDistanceA, oldPartsShowView.y, oldPartsShowView.width, TitleTFViewHeight) title:@"备胎检查" addTarget:nil selector:nil];
        NSArray *spareWheelCheckDataArray = [ICrEAMTool getParameterArrayWithCode:ICMEnumIntToString(ICMEnumYESOrNOPre)];
        spareWheelCheckView.clickDataArray = [[ICrEAMTool getParameterTitleArrayWithArray:spareWheelCheckDataArray] mutableCopy];
        [self.bigScrollView addSubview:spareWheelCheckView];
        
        ICMTitleTextFeildView *sendCarAddressView = [ICMTitleTextFeildView createEditableICMTitleTextFeildViewWithFrame:CGRectMake(spareWheelCheckView.rightEdge+xDistanceB, spareWheelCheckView.y, ActualWidth(465), TitleTFViewHeight) title:@"送车地址"];
        sendCarAddressView.limitedNum = 100;
        [self.bigScrollView addSubview:sendCarAddressView];
        
        self.cleanCarView = cleanCarView;
        self.oldPartsShowView = oldPartsShowView;
        self.spareWheelCheckView = spareWheelCheckView;
        self.sendCarAddressView = sendCarAddressView;
        
        //第五行
        ICMTitleTextView *repairTypeView = [ICMTitleTextView createICMTitleClickTextViewWithFrame:CGRectMake(cleanCarView.x, cleanCarView.bottomEdge+yDistance, ActualWidth(220), TitleTViewHeight) title:@"维修类型" textViewHeight:ActualHeight(100) addTarget:self selector:@selector(clickRepairType)];
        [self.bigScrollView addSubview:repairTypeView];
        
        ICMTitleTextView *requirementDiscribeView = [ICMTitleTextView creatICMTitleTextViewWithFrame:CGRectMake(repairTypeView.rightEdge+xDistanceA, repairTypeView.y, ActualWidth(465), TitleTViewHeight) title:@"需求描述" textViewHeight:ActualHeight(100)];
        requirementDiscribeView.limitedNum = 100;
        [self.bigScrollView addSubview:requirementDiscribeView];
        
        ICMTitleTextView *furtherCheckView = [ICMTitleTextView creatICMTitleTextViewWithFrame:CGRectMake(requirementDiscribeView.rightEdge+xDistanceA, requirementDiscribeView.y, spareWheelCheckView.rightEdge+xDistanceB + ActualWidth(465) - requirementDiscribeView.rightEdge - xDistanceA, TitleTViewHeight) title:@"进一步检查" textViewHeight:ActualHeight(100)];
        furtherCheckView.limitedNum = 100;
        [self.bigScrollView addSubview:furtherCheckView];
        
        self.repairTypeView = repairTypeView;
        self.requirementDiscribeView = requirementDiscribeView;
        self.furtherCheckView = furtherCheckView;
        
        UIView *firstSeparator = [[UIView alloc] initWithFrame:CGRectMake(self.centerX, yDistance, 1, customerPhoneNumberView.bottomEdge+ActualHeight(10)-yDistance)];
        firstSeparator.backgroundColor = SepColor_gray;
        [self.bigScrollView addSubview:firstSeparator];
        
        UIView *secondSeparetor = [[UIView alloc] initWithFrame:CGRectMake(vinNumberView.x, customerPhoneNumberView.bottomEdge+yDistance, customerPhoneNumberView.rightEdge-vinNumberView.x, 1)];
        secondSeparetor.backgroundColor = SepColor_gray;
        [self.bigScrollView addSubview:secondSeparetor];
        
        
        //点击icon
        UIButton *qrcodeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        qrcodeBtn.frame = CGRectMake(ActualWidth(215), ActualHeight(25), ActualWidth(23), ActualWidth(23));
        [qrcodeBtn setUpButtonWithNormolTitle:nil selectedTitle:nil normolTitleSize:0 selectedTitleSize:0 normolTitleColor:nil selectedTitleColor:nil normolBcakImage:[UIImage imageNamed:GetCar_Scan] selectedBackImage:nil actionSEL:@selector(clickQRCodeBtn) target:self];
        [self.bigScrollView addSubview:qrcodeBtn];
        [ICrEAMTool createAndAddBiggerButtonForButton:qrcodeBtn andSEL:@selector(clickQRCodeBtn) target:self addTop:15 bottom:0 left:15 right:15 inView:self.bigScrollView];
        
        UIButton *carInfoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        carInfoBtn.frame = CGRectMake(ActualWidth(390), ActualHeight(25), ActualWidth(23), ActualWidth(23));
        [carInfoBtn setUpButtonWithNormolTitle:nil selectedTitle:nil normolTitleSize:0 selectedTitleSize:0 normolTitleColor:nil selectedTitleColor:nil normolBcakImage:[UIImage imageNamed:Appointment_CarInfo] selectedBackImage:nil actionSEL:@selector(clickCarInfoBtn) target:self];
        [self.bigScrollView addSubview:carInfoBtn];
        [ICrEAMTool createAndAddBiggerButtonForButton:carInfoBtn andSEL:@selector(clickCarInfoBtn) target:self addTop:15 bottom:0 left:15 right:15 inView:self.bigScrollView];
        
        UIButton *monitorBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        monitorBtn.frame = CGRectMake(ActualWidth(460), ActualHeight(25), ActualWidth(23), ActualWidth(23));
        [monitorBtn setUpButtonWithNormolTitle:nil selectedTitle:nil normolTitleSize:0 selectedTitleSize:0 normolTitleColor:nil selectedTitleColor:nil normolBcakImage:[UIImage imageNamed:Appointment_CarMonitor] selectedBackImage:nil actionSEL:@selector(clickMonitorBtn) target:self];
        [self.bigScrollView addSubview:monitorBtn];
        [ICrEAMTool createAndAddBiggerButtonForButton:monitorBtn andSEL:@selector(clickMonitorBtn) target:self addTop:15 bottom:0 left:15 right:15 inView:self.bigScrollView];
        
        UIButton *carOwnerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        carOwnerBtn.frame = CGRectMake(ActualWidth(965), ActualHeight(25), ActualWidth(23), ActualWidth(23));
        [carOwnerBtn setUpButtonWithNormolTitle:nil selectedTitle:nil normolTitleSize:0 selectedTitleSize:0 normolTitleColor:nil selectedTitleColor:nil normolBcakImage:[UIImage imageNamed:Appointment_CarOwner] selectedBackImage:nil actionSEL:@selector(clickCarOwnerBtn) target:self];
        [self.bigScrollView addSubview:carOwnerBtn];
        [ICrEAMTool createAndAddBiggerButtonForButton:carOwnerBtn andSEL:@selector(clickCarOwnerBtn) target:self addTop:15 bottom:0 left:15 right:15 inView:self.bigScrollView];
        
        self.bigScrollView.contentSize = CGSizeMake(ScreenWidth, furtherCheckView.bottomEdge);
        [self addSubview:self.bigScrollView];
    }
    return self;
}
#pragma mark    油量变化
- (void)remainingFuelSliderChanged:(UISlider *)sender{
    int value = roundf(sender.value);
    sender.value = value;
    self.remainingFuel = value*10;
    [self setupRemainingFuelView];
}

- (void)setupRemainingFuelView{
    self.remainingFuelLabel.text = [NSString stringWithFormat:@"%d%%", self.remainingFuel];
    
    float centerX = self.oilIndicator.bounds.size.width/2;
    float centerY = self.oilIndicator.bounds.size.height/2;
    float x = self.oilIndicator.bounds.size.width-ActualWidth(3);
    float y = self.oilIndicator.bounds.size.height/2;
    
    CGAffineTransform trans = GetCGAffineTransformRotateAroundPoint(centerX,centerY ,x ,y ,(self.remainingFuel*1.8)/180.0*M_PI);
    self.oilIndicator.transform = CGAffineTransformIdentity;
    self.oilIndicator.transform = trans;
}
#pragma mark    选择了车牌地
- (void)didSelectAreaPrefix:(NSString *)prefix {
    if ([prefix isEqualToString:@"其他"]) {
        [Window addSubview:self.inputAreaView];
        [self.inputAreaView.inputAreaTextView.contentTextFeild becomeFirstResponder];
        return;
    }
    
//    BOOL isChange = ![self.selectAreaView.contentText isEqualToString:prefix];
    self.selectAreaView.contentText = prefix;
    [self.plateNumberView.contentTextFeild becomeFirstResponder];
//    if (isChange&&self.plateNumberView.contentText.length>4&&[self.delegate respondsToSelector:@selector(licenseDidEndEdit:type:)]) {
//        [self.delegate licenseDidEndEdit:self.plateNumberView type:@"1"];
//    }
}

- (UIView *)inputAreaView{
    if (!_inputAreaView) {
        _inputAreaView = [ICMInputAreaView createInputAreaView];
        _inputAreaView.delegate = self;
    }
    return _inputAreaView;
}

- (void)inputAreaViewWillDisappearWithText:(NSString *)text{
    [self didSelectAreaPrefix:text];
}

- (void)clickSelectAreaView:(ICMTitleTextFeildView *)view {
    [Window addSubview:self.selectAreaPrefixView];
}

#pragma mark -- 车主车辆信息回调

- (void)clickRepairType{
    [self endEditing:YES];
    if ([self.delegate respondsToSelector:@selector(clickRepairTypeBtn)]) {
        [self.delegate clickRepairTypeBtn];
    }
}

- (void)clickQRCodeBtn{
    if ([self.delegate respondsToSelector:@selector(clickQRCodeBtnWithType:)]) {
        [self.delegate clickQRCodeBtnWithType:0];
    }
}

- (void)clickCarInfoBtn{
    if ([self.delegate respondsToSelector:@selector(clickCarInfoBtn)]) {
        [self.delegate clickCarInfoBtn];
    }
    
}

- (void)clickMonitorBtn{
    if ([self.delegate respondsToSelector:@selector(clickMonitorBtn)]) {
        [self.delegate clickMonitorBtn];
    }
}

- (void)clickCarOwnerBtn{
    if ([self.delegate respondsToSelector:@selector(clickCarOwnerBtn)]) {
        [self.delegate clickCarOwnerBtn];
    }
}
#pragma mark    根据model设置界面
- (void)setupBasicInfoViewWithModel:(ICMBasicInfoModel*)basicInfoModel{
    
    self.vinNumberView.contentTextFeild.userInteractionEnabled = NO;
//    self.selectAreaView.userInteractionEnabled = NO;
//    self.plateNumberView.contentTextFeild.userInteractionEnabled = NO;
    
    self.RECEPTION_NO = basicInfoModel.RECEPTION_NO;
    self.vinNumberView.contentText = basicInfoModel.VIN;
    NSString *area = @"";
    NSString *plant = @"";
    if (basicInfoModel.LICENSE.length>2) {
        area = [basicInfoModel.LICENSE substringWithRange:NSMakeRange(0, 1)];
        plant = [basicInfoModel.LICENSE substringWithRange:NSMakeRange(1, basicInfoModel.LICENSE.length-1)];
        unsigned char mCode;
        sscanf([area UTF8String], "%c", &mCode);
        
        if (mCode <= 'Z' && mCode >= 'A') {
            area = [basicInfoModel.LICENSE substringWithRange:NSMakeRange(0, 2)];
            plant = [basicInfoModel.LICENSE substringWithRange:NSMakeRange(2, basicInfoModel.LICENSE.length-2)];
        }
    }
    self.selectAreaView.contentText = area;
    self.plateNumberView.contentText = plant;
    self.ownerNameView.contentText = basicInfoModel.OWNER_NAME;
    self.invoiceDateView.contentText = (!basicInfoModel.SALES_DATE || [basicInfoModel.SALES_DATE isEqualToString:@"0"] || [basicInfoModel.SALES_DATE doubleValue] < 0)?@"":[ICrEAMTool getDateWithTimeInterval:basicInfoModel.SALES_DATE];
    
    self.currentMileageView.contentText = basicInfoModel.IN_MILEAGE;
//    if(_isEditType){
//        self.current_mile = [basicInfoModel.LAST_MAINTAIN_MILEAGE integerValue];
//    }else{
//        self.current_mile = [basicInfoModel.LAST_MAINTAIN_MILEAGE integerValue];
//    }
    self.current_mile = [basicInfoModel.LAST_MAINTAIN_MILEAGE integerValue];
    self.currentMileageView.mileageLabel.text = [NSString stringWithFormat:@"%ld",self.current_mile];
    self.ownerPhoneNumberView.contentText = basicInfoModel.OWNER_MOBILE;
    self.ownerTypeView.contentText = [ICrEAMTool getCodeModelForCode:basicInfoModel.OWNER_PROPERTY].desc;
    self.carTypeView.contentText = [NSString stringWithFormat:@"%@|%@",basicInfoModel.MODEL_CODE,basicInfoModel.MODEL_NAME];
    self.carTypeView.noStr = basicInfoModel.MODEL_CODE;
    // 油量
    self.remainingFuelSlider.value = [basicInfoModel.OIL_REMAIN intValue]/10;
    self.remainingFuel = [basicInfoModel.OIL_REMAIN intValue];
    [self setupRemainingFuelView];
    self.haveChangeVIN = YES;
    self.haveChangeCarModel = YES;
    self.customerNameView.contentText = basicInfoModel.DELIVERER==nil?basicInfoModel.OWNER_NAME:basicInfoModel.DELIVERER;
    self.customerPhoneNumberView.contentText = basicInfoModel.DELIVERER_MOBILE==nil?basicInfoModel.OWNER_MOBILE:basicInfoModel.DELIVERER_MOBILE;
    self.cleanCarView.contentText = [ICrEAMTool getCodeModelForCode:basicInfoModel.WASH_TYPE].desc;
    self.oldPartsShowView.contentText = [ICrEAMTool getCodeModelForCode:basicInfoModel.OLD_PART_PROCESS].desc;
    self.spareWheelCheckView.contentText = [ICrEAMTool getCodeModelForCode:basicInfoModel.CHECK_SPARE_WHEEL].desc;
    self.sendCarAddressView.contentText = basicInfoModel.DELIVERY_ADDRESS;
    
    NSMutableArray *repiarDescs = [NSMutableArray array];
    NSArray *repiarCodes = [basicInfoModel.REPAIR_TYPE_CODE componentsSeparatedByString:@";"];
    for (NSString *code in repiarCodes) {
        NSString *desc = [ICrEAMTool getRepiarTypeDescWithRepiarCode:code];
        [repiarDescs PACA_AddObject:desc];
    }
    self.repairTypeView.contentText = [repiarDescs componentsJoinedByString:@","];
    
    self.requirementDiscribeView.contentText = basicInfoModel.BUSINESS_DESC;
    self.furtherCheckView.contentText = basicInfoModel.DEPTH_CHECK;
    
 
}

- (void)setupBasicInfoViewWithModel:(ICMBasicInfoModel *)basicInfoModel andOtherInfoModel:(ICMAppointmentOtherInfoModel *)otherInfoModel{
//    basicInfoModel.LAST_MAINTAIN_MILEAGE = @"";
    self.vinNumberView.contentTextFeild.userInteractionEnabled = YES;
    self.selectAreaView.contentTextFeild.userInteractionEnabled = YES;
    self.plateNumberView.contentTextFeild.userInteractionEnabled = YES;
    
    self.RECEPTION_NO = basicInfoModel.RECEPTION_NO;
    self.vinNumberView.contentText = basicInfoModel.VIN;
    NSString *area = @"";
    NSString *plant = @"";
    if (basicInfoModel.LICENSE.length>2) {
        area = [basicInfoModel.LICENSE substringWithRange:NSMakeRange(0, 1)];
        plant = [basicInfoModel.LICENSE substringWithRange:NSMakeRange(1, basicInfoModel.LICENSE.length-1)];
        unsigned char mCode;
        sscanf([area UTF8String], "%c", &mCode);
        if (mCode <= 'Z' && mCode >= 'A') {
            area = [basicInfoModel.LICENSE substringWithRange:NSMakeRange(0, 2)];
            plant = [basicInfoModel.LICENSE substringWithRange:NSMakeRange(2, basicInfoModel.LICENSE.length-2)];
        }
    }
    self.selectAreaView.contentText = area;
    self.plateNumberView.contentText = plant;
    self.ownerNameView.contentText = basicInfoModel.OWNER_NAME;
    self.invoiceDateView.contentText = [ICrEAMTool getDateWithTimeInterval:basicInfoModel.SALES_DATE];
//    self.currentMileageView.contentText = basicInfoModel.IN_MILEAGE;
//    if(IsStrEmpty(basicInfoModel.LAST_MAINTAIN_MILEAGE)){
//        basicInfoModel.LAST_MAINTAIN_MILEAGE = @"";
//    }
    self.currentMileageView.mileageLabel.text = basicInfoModel.LAST_MAINTAIN_MILEAGE;
    self.current_mile = [basicInfoModel.IN_MILEAGE integerValue];
    self.ownerPhoneNumberView.contentText = basicInfoModel.OWNER_MOBILE;
    self.ownerTypeView.contentText = [ICrEAMTool getCodeModelForCode:basicInfoModel.OWNER_PROPERTY].desc;
    self.carTypeView.contentText = [NSString stringWithFormat:@"%@|%@",basicInfoModel.MODEL_CODE,basicInfoModel.MODEL_NAME];
    self.carTypeView.noStr = basicInfoModel.MODEL_CODE;
    // 油量
    self.remainingFuelSlider.value = [basicInfoModel.OIL_REMAIN intValue]/10;
    self.remainingFuel = [basicInfoModel.OIL_REMAIN intValue];
    [self setupRemainingFuelView];
    self.haveChangeVIN = YES;
    self.haveChangeCarModel = YES;
    self.customerNameView.contentText = otherInfoModel.CONTACTOR_NAME;
    self.customerPhoneNumberView.contentText = otherInfoModel.CONTACTOR_MOBILE;

    self.sendCarAddressView.contentText = basicInfoModel.DELIVER_ADD;
    
    NSMutableArray *repiarDescs = [NSMutableArray array];
    NSArray *repiarCodes = [otherInfoModel.BOOKING_REPAIR_TYPE componentsSeparatedByString:@";"];
    for (NSString *code in repiarCodes) {
        NSString *desc = [ICrEAMTool getRepiarTypeDescWithRepiarCode:code];
        [repiarDescs PACA_AddObject:desc];
    }
    self.repairTypeView.contentText = [repiarDescs componentsJoinedByString:@","];
    
    self.requirementDiscribeView.contentText = otherInfoModel.REMARK;
}

+ (instancetype)createICMGetCarBasicInfoViewWithFrame:(CGRect)frame{
    return [[ICMGetCarBasicInfoView alloc] initWithFrame:frame];
}

CGAffineTransform  GetCGAffineTransformRotateAroundPoint(float centerX, float centerY ,float x ,float y ,float angle)
{
    x = x - centerX; //计算(x,y)从(0,0)为原点的坐标系变换到(CenterX ，CenterY)为原点的坐标系下的坐标
    y = y - centerY; //(0，0)坐标系的右横轴、下竖轴是正轴,(CenterX,CenterY)坐标系的正轴也一样
    
    CGAffineTransform  trans = CGAffineTransformMakeTranslation(x, y);
    trans = CGAffineTransformRotate(trans,angle);
    trans = CGAffineTransformTranslate(trans,-x, -y);
    return trans;
}

- (void)editableViewDidEndEdit:(ICMTitleTextFeildView *)sender{
    if (sender == self.vinNumberView) {
        self.haveChangeVIN = YES;
        if ([self.delegate respondsToSelector:@selector(licenseDidEndEdit:type:)]) {
            [self.delegate licenseDidEndEdit:sender type:@"0"];
        }
    }else if (sender == self.plateNumberView){
        if ([self.delegate respondsToSelector:@selector(licenseDidEndEdit:type:)]) {
            [self.delegate licenseDidEndEdit:sender type:@"1"];
        }
    }else if (sender == self.selectAreaView){
        
    }else if (sender == self.currentMileageView){
//        NSInteger mile = [self.currentMileageView.contentText integerValue];
//        if (mile<self.current_mile) {
//            self.currentMileageView.contentText = [@(self.current_mile) stringValue];
//            [self showString:@"进站里程应大于上次进站里程，请检查！" forSeconds:1.5];
//        }
    }else if (sender == self.carTypeView){
        self.haveChangeCarModel = YES;
    }
}


@end
